<template>
    <div class="card-page">
        <tool-bar nav="" :title="action_name + 'Api测试'">
            <el-button size="mini" @click="$router.push('/dev/api-exec-test/add')" v-if="$props.action=='edit'">新建</el-button>
            <el-button size="mini" @click="save_click" type="primary">保存</el-button>
        </tool-bar>
        <el-row :gutter="12" type="flex">
            <el-col>
                <el-card shadow="always">
                    <div slot="header">
                        <span>基本信息</span>
                    </div>
                </el-card>
            </el-col>
            <el-col>
                <el-card shadow="always">
                    <div slot="header">
                        <span>扩展信息</span>
                    </div>
                </el-card>
            </el-col>
        </el-row>
        <div>
<!--            <ref-api-instance title="instance" v-model="info.instance">-->
<!--            </ref-api-instance>-->
<!--            <ref-id-name title="createBy" v-model="info.createBy">-->
<!--            </ref-id-name>-->

        </div>
    </div>
</template>

<script setup>
/**
 * Created by CodeGenerator  at 2024-03-01 23:35:08
 */
// import RefApiInstance from "./ref-api-instance"




//定义 vue2的this,当前组件
const $self = getCurrentInstance();

//定义 $attrs
const $attrs = useAttrs();



//定义data
const $data = reactive({
    info: {
        instance: {},
        createBy: {},
    }, //子对象需要声明。

    HttpMethod: jv.enum.HttpMethod.getData(),
    ApiParameterTypeEnum: jv.enum.ApiParameterTypeEnum.getData(),
    ApiParameterStringTypeEnum: jv.enum.ApiParameterStringTypeEnum.getData(),
});
const info = $computed(()=> $data.info );

const $props = defineProps({
    action: { type: String } ,
    id : { type: String }
});




const list = ref();

//定义事件
const $emit = defineEmits(["update:modelValue","loaded"]);

const action = $computed( function() {
    return $props.id ? "edit" : "add";
});
const action_name = $computed( function() {
    return {add: "添加", edit: "修改"}[$props.action]
});

const loadData = async function() {
    if (!$props.id) return;
    let res = await this.$http.post("/dev/api-exec-test/detail/" + $props.id)
    $data.info = res.data.data;
};
const save_click = async function() {
//校验
    if (this.chk() == false) {
        return;
    }
    let res = await this.$http.post("/dev/api-exec-test/save", $data.info)
//[axios拦截器中已处理了异常]。
    jv.info(action_name + " 成功");
    let id = res.data.data || $data.info.id;
    if (!id) {
        return jv.error("找不到 id");
    }
    jv.$router.push("/dev/api-exec-test/edit/" + id);
};

onMounted( function() {
    loadData();
} )



</script>

<style scoped lang="scss">
</style>
